package org.example.xls.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.xls.common.PageResult;
import org.example.xls.common.Result;
import org.example.xls.pojo.TestQuestion;
import org.example.xls.service.TestQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/testQuestion")
public class TestQuestionController {
    @Autowired
    private TestQuestionService testQuestionService;

    /**
     * 获取测评方案的问题
     * @param testId
     * @return
     */
    @GetMapping
    public List<TestQuestion> testQuestion(Integer testId) {
        List<TestQuestion> testQuestion = testQuestionService.getTestQuestion(testId+1);
        return testQuestion;
    }

    /**
     * 获取测评方案的问题个数
     * @param testId
     * @return
     */
    @GetMapping("/length")
    public Integer testQuestionLength(Integer testId) {
        Integer testQuestion = testQuestionService.getCount(testId+1);
        return testQuestion;
    }
    /**
     * 分页查询测评记录
     */
    @GetMapping("/page")
    public Result<PageResult> testQuestionPage( String openId, Integer page, Integer size) {
        log.info("分页查询测评记录,openId:{},page:{},size:{}", openId, page, size);
        PageResult pageResult = testQuestionService.getTestQuestionPage(openId, page, size);
        return  Result.success(pageResult);
    }
}
